package org.ddr.control;

import java.io.IOException;
import java.lang.reflect.Method;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public abstract class ControlServlet extends HttpServlet {

	public ControlServlet() {
		super();
	}

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String path = request.getPathInfo().substring(1);

		System.out.println(path);

		Class clz = this.getClass();
		try {
			Method targetMethod = clz.getMethod(path, HttpServletRequest.class,
					HttpServletResponse.class);

			targetMethod.invoke(this, request, response);

		} catch (Exception e) {
			RequestDispatcher dispatcher = request
					.getRequestDispatcher("/WEB-INF/jsp/member/login.jsp");
			dispatcher.forward(request, response);
		}
	}
}